var tp_arr = new Array(
    "/static/app/transverse/system/auth03/detail/index.htm"
);
var code = window.getUrlParam("c");
var rf_url = window.getUrlParam("rf");
console.log(window.location);
window.current = new Vue({
    el: '#current',
    template: window.getTemplate(tp_arr),
    data: {
        rfUrl : rf_url,
        code: code ? code : '',
        orderList: [],
        agentSumFind: ''
    },
    // 属性监听器
    watch: {},
    filters: {
        _formatDate: function (val) {
            return window.dateTimeFormat(val, "yyyy-MM-dd h:m:s");
        },
        _formatMoney: function (val) {
            var money = parseFloat(val);
            return window.formatMoney(money, 0);
        },
        _orderState: function (info) {
            return window.getOrderState(info['fCFlag'], info['fProNtfFlag'], info['fOutFlag'], info['fIfClose'], info['fIfCancel']);
        },
        _orderType: function (val) {
            var type_name;
            switch (val) {
                case 'M':
                    type_name = '店智';
                    break;
                case '1':
                    type_name = '系统';
                    break;
                default:
                    type_name = '未知';
                    break;

            }
            return type_name;
        },
        _getRowsColor: function (index) {
            var className = 'even';
            if(index % 2 == 0){
                className = '';
            }
            return className;
        },
        _getTargetProportion: function (type) {
            var styleVal = 'width: 0%;';
            var proportion = 0;
            var info = window.current['agentSumFind'];
            if(info != ''){
                if(type == 0){
                    proportion = (parseFloat(info['target1_sum']) + parseFloat(info['target2_sum']) + parseFloat(info['target3_sum'])) / (parseFloat(info['target1_value']) + parseFloat(info['target2_value']) + parseFloat(info['target3_value'])) * 100;
                } else {
                    proportion = parseFloat(info['target' + type + '_sum']) / parseFloat(info['target' + type + '_value']) * 100;
                }
            }
            proportion = parseFloat(proportion.toFixed(2));
            if(proportion > 0){
                styleVal = 'width: ' + proportion +'%;';
            }
            return styleVal;
        },
        _totalTargetFormatMoney: function (type) {
            var money = 0;
            var info = window.current['agentSumFind'];
            if(info != ''){
                if(type == 1){
                    money = parseFloat(info['target1_sum']) + parseFloat(info['target2_sum']) + parseFloat(info['target3_sum']);
                }
                if(type == 2){
                    money = parseFloat(info['target1_value']) + parseFloat(info['target2_value']) + parseFloat(info['target3_value']);
                }
            }
            return window.formatMoney(money, 0);
        },
        _getProportion: function (type) {
            var proportion = 0;
            var info = window.current['agentSumFind'];
            if(info != ''){
                if(type == 0){
                    proportion = (parseFloat(info['target1_sum']) + parseFloat(info['target2_sum']) + parseFloat(info['target3_sum'])) / (parseFloat(info['target1_value']) + parseFloat(info['target2_value']) + parseFloat(info['target3_value'])) * 100;
                } else {
                    proportion = parseFloat(info['target' + type + '_sum']) / parseFloat(info['target' + type + '_value']) * 100;
                }
            }
            return proportion?proportion.toFixed(2) : 0;
        },
        _currPage: function (val) {
            var page = window.current['page'];
            var className = 'footable-page';
            if(page == val){
                className = ['footable-page', 'active']
            }
            return className;
        }
    },
    computed: {},
    methods: {
        onBackOff: function () {
            window.to_back_off();
        },
        onRefresh: function () {
            window.location.href = window.location.pathname + window.location.search;
        },
        onSaveIntention: function () {
            window.save_partner_intention();
        }
    }
});

window.get_order_list = function () {
    var code = window.current['code'];
    var data_arr = {
        code : code
    };
    window.ajax({
        url: "/service/Partypromotion/getAgentOrderList",
        data: data_arr,
        async: false,
        success: function (d) {
            if (d['status'] == 1) {
                var list = d['data'];
                if (list) {
                    window.current['orderList'] = list;
                } else {
                    window.current['orderList'] = [];
                }
                window.get_agent_sum();
            } else {
                window.custom_toast(d['msg']);
                window.to_back_off();
            }
        }
    });
}

window.get_agent_sum = function () {
    var keyword = window.current['code'];
    var region_id = window.current['regionID'];
    var data_arr = {
        keyword : keyword,
        region_id : region_id
    };
    window.ajax({
        url: "/service/Partypromotion/getAgentSum",
        data: data_arr,
        async: false,
        success: function (d) {
            if (d['status'] == 1) {
                var data = d['data'];
                if (data) {
                    window.current['agentSumFind'] = data;
                } else {
                    window.current['agentSumFind'] = '';
                }
            } else {
                window.custom_toast(d['msg']);
            }
        }
    });
}

window.to_back_off = function(){
    var rf_url = window.current['rfUrl'];
    if(!rf_url){
        rf_url = "/system/Auth03/agent.html";
    }
    window.location.href = rf_url;
}

window.get_order_list();
